var utils = require("../../../utils/util.js");
var app = getApp();
Page({
  data: {
    arr:[],
    balance:0,
    hasData: true,
    canScroll: true,
    pageSize: 10,
    pageIndex: 1
  },
  onLoad:function(){

  },
  lower:function(){
    if (this.data.canScroll){
      let me = this;
      wx.showLoading({
        title: '加载中',
      })
      wx.request({
        url: utils.dominame + '/api/v1/commission/mybalanceDetail',
        data: {
          time_interval: 1,
          token: app.globalData.token,
          pageSize: 10,
          pageIndex: 1
        },
        method: "GET",
        header: {
          "Content-Type": "application/x-www-form-urlencoded"  //post
        },
        complete: function (res) {
          wx.hideLoading();
        },
        success: function (res) {
          console.log(res);
          if (res.data.code == 0) {
            var arrBox;
            if (me.data.pageIndex == 1) {
              me.setData({
                balance: parseFloat(res.data.data.user_balance).toFixed(2)
              })
              arrBox = res.data.data.table.rows;
            } else {
              arrBox = me.data.arr.concat(res.data.data.table.rows)
            };
            console.log(me.data.arr.concat(res.data.data.table.rows));
            if (me.data.pageSize * me.data.pageIndex < res.data.data.table.recordCount) {
              var num = me.data.pageIndex + 1;
              me.setData({
                arr: arrBox,
                hasData: true,
                pageIndex: num
              });
            } else {
              me.setData({
                arr: arrBox,
                hasData: false,
                canScroll: false
              });
            }
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: "none"
            })
          }
        }
      })
    }
  },
  onShow: function () {
    this.setData({
      pageIndex: 1,
      canScroll: true,
      hasData:true
    });
    this.lower();
  },
  goRecharge:function(){
    wx.navigateTo({
      url: '../recharge/recharge',
    })
  }
})